// const API_HOST = 'http://chcapi.wenstech.com/api/foo.php';
const API_HOST = 'https://api.huacheng-xiaochengxu.com/musoundic/api/foo.php';
export const COS_HOST = 'https://chc-1326568539.cos.ap-nanjing.myqcloud.com/';

export const httpServer = (method, c, m , args = null) => {
  if (!args) {
    args = {};
  }

  args.openid = wx.getStorageSync('openid') || '';
  return new Promise((resolve, reject) => {
    wx.request({
      url: API_HOST,
      method,
      header: {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
      },
      data: {
        c,
        m,
        args: JSON.stringify(args),
      },
      success: res => {
        if (res.statusCode == 200) {
          resolve(res.data);
        } else {
          reject(res);
        }
      },
      fail: res => {
        wx.showToast({
          icon: 'none',
          title: '网络异常，请稍后重试',
        });
        reject(res);
      }
    })
  })
};